package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    /**
     * 新增地址薄
     * @param addressBook
     */
    @Insert("insert into address_book (user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label) VALUES " +
            "(#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label})")
    void insert(AddressBook addressBook);

    /**
     * 查询地址信息
     * @return
     */
    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> list(Long userId);

    /**
     * 根据地址薄id查询地址信息
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long id);

    /**
     * 根据地址薄id修改地址信息
     * @param addressBook
     */
    void update(AddressBook addressBook);

    /**
     * 根据地址薄id删除地址信息
     *
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void del(Long id);

    /**
     * 将所有地址的默认地址设置为0
     * @param list
     */
    void setAllAddressBookNotDefault(List<AddressBook> list);

    /**
     * 查询默认地址信息
     * @return
     */
    AddressBook getDefault();

}
